import { http } from "@/utils/http";

/**
 * 获取代理商列表
 */
export const getAdminAgentsList = (params?: {
  page: number;
  size: number;
  keyword?: string;
  enabled?: boolean | string;
}) => {
  return http.request<any>("get", "/api/admin/agents/list", { params });
};

/**
 * 获取代理商品牌logo
 */
export const getAdminAgentsLogo = (agentId: string | number) => {
  return http.request<any>(
    "get",
    `/api/admin/agents/${agentId}/brand/logo?format=image`,
    {
      responseType: "blob",
      hideMessage: true
    }
  );
};

/**
 * 启用代理商
 */
export const enableAdminAgents = (agentId: string | number) => {
  return http.request<any>("post", `/api/admin/agents/${agentId}/enable`);
};

/**
 * 禁用代理商
 */
export const disableAdminAgents = (agentId: string | number) => {
  return http.request<any>("post", `/api/admin/agents/${agentId}/disable`);
};

/**
 * 降级代理商为普通用户
 */
export const demoteAdminAgents = (agentId: string | number) => {
  return http.request<any>("post", `/api/admin/agents/${agentId}/demote`);
};

/**
 * 重置代理商Token
 */
export const resetAdminAgentsToken = (agentId: string | number) => {
  return http.request<any>(
    "post",
    `/api/admin/agents/${agentId}/config/token/reset`
  );
};

/**
 * 重置代理商ApiKey
 */
export const resetAdminAgentsApiKey = (agentId: string | number) => {
  return http.request<any>(
    "post",
    `/api/admin/agents/${agentId}/config/apikey/reset`
  );
};

/**
 * 设置用户为代理商
 */
export const setAdminAgents = (userId: string | number) => {
  return http.request<any>("post", `/api/admin/agents/create/${userId}`);
};

/**
 * 清理代理商配置缓存
 */
export const clearAdminAgentsConfigCache = () => {
  return http.request<any>("post", `/api/admin/agents/config/cache/clear`);
};

/**
 * 获取代理商完整配置
 */
export const getAdminAgentsConfig = (agentId: string | number) => {
  return http.request<any>("get", `/api/admin/agents/${agentId}/config`);
};

/**
 * 更新代理商Telegram配置
 */
export const updateAdminAgentsTelegramConfig = (
  agentId: string | number,
  data: {
    botToken: string;
    botName: string;
  }
) => {
  return http.request<any>(
    "put",
    `/api/admin/agents/${agentId}/config/telegram`,
    {
      data
    }
  );
};

/**
 * 更新代理商支付配置
 */
export const updateAdminAgentsPaymentConfig = (
  agentId: string | number,
  data: {
    walletAddress: string;
  }
) => {
  return http.request<any>(
    "put",
    `/api/admin/agents/${agentId}/config/payment`,
    {
      data
    }
  );
};

/**
 * 更新代理商名称
 */
export const updateAdminAgentsBrandName = (
  agentId: string | number,
  data: {
    brandName: string;
  }
) => {
  return http.request<any>(
    "put",
    `/api/admin/agents/${agentId}/config/brand/name`,
    {
      data
    }
  );
};

//同步代理商服务类型价格（从主系统）
export const syncAgentServicePricesFromMain = (
  agentId: string | number,
  data: {
    override: boolean;
  }
) => {
  return http.request<any>(
    "post",
    `/api/admin/agents/${agentId}/config/price/service/sync-from-main`,
    {
      data
    }
  );
};
